//
//  GTSearchBar.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/27.
//

#import "../../Utils/GTScreen.h"
#import "GTSearchBar.h"
@interface GTSearchBar ()<UITextFieldDelegate>
@property (nonatomic, strong, readwrite) UITextField *textField;

@end

@implementation GTSearchBar
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];

    if (self) {
		[self addSubview:({
			self.textField = [[UITextField alloc]initWithFrame:CGRectMake(UI(10),
																		  UI(7),
																		  frame.size.width - UI(10)*2,
																		  frame.size.height - UI(7) * 2)];
			self.textField.backgroundColor = [UIColor whiteColor];
			self.textField.delegate = self;
			self.textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
			self.textField.leftViewMode = UITextFieldViewModeAlways;
			self.textField.placeholder = @"今日头条推荐";
			self.textField.clearButtonMode = UITextFieldViewModeUnlessEditing;
			self.textField;
		})];
    }

    return self;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[self.textField resignFirstResponder];
    return YES;
}

@end
